package com.dao;

import com.mapper.MemberMapper;
import com.mapper.OrderNewMapper;
import com.model.Member;
import com.model.MemberExample;
import com.model.OrderNew;
import com.model.OrderNewExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by yangziqiang on 16-9-16.
 */


@Repository
public class MemberDao {

    @Autowired private MemberMapper memberMapper;
    @Autowired private OrderNewMapper orderNewMapper;
    /**
     * 添加用户
     * @param member
     * @return
     */
    public int addMember(Member member){
         return  memberMapper.insertSelective(member);
    }

    public Member queryByMember(String mobile){
        MemberExample example = new MemberExample();
        example.createCriteria().andMobileEqualTo(mobile);
        List<Member> members = memberMapper.selectByExample(example);
        if (members.size() >0 )
            return members.get(0);
        else
        return null;
    }
    public Member queryMemBerByid(String userid){
        MemberExample example = new MemberExample();
        example.createCriteria().andIdEqualTo(userid);
        List<Member> members = memberMapper.selectByExample(example);
        if (members.size() >0 )
            return members.get(0);
        else
            return null;
    }
    /**
     * 根据会员id查询会员信息
     * @param memberid
     * @return
     */
    public Member queryMemberById(String memberid){
        return  memberMapper.selectByPrimaryKey(memberid);
    }



    public int plinsert(List <Member> members){

        return  memberMapper.plinsert(members);
    }


    public List<OrderNew> finList() {
        OrderNewExample example =new OrderNewExample();
        example.createCriteria().andIdIsNotNull();
       return orderNewMapper.selectByExample(example);
    }
}
